//
//  LDJ_DetailBaseViewController.m
//  Pianke
//
//  Created by dllo on 15/12/26.
//  Copyright © 2015年 dada. All rights reserved.
//


#import "LDJ_DetailBaseViewController.h"

@interface LDJ_DetailBaseViewController ()

@end

@implementation LDJ_DetailBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
#pragma waring - 还么有用masonry加约束
    
    // Do any additional setup after loading the view.
    //创建返回按钮
    self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame = CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.height, self.navigationController.navigationBar.frame.size.height);
    self.backButton.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.backButton];
    
//    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
//       
//        make.top.left.mas_equalTo(0);
//        make.size.mas_equalTo(CGSizeMake(44 * EACH_WIDTH, 44 * EACH_HEIGHT));
//        
//        
//    }];
    
    //创建返回图标放在返回按钮上
    self.backButtonImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.backButton.frame.size.width / 4, self.backButton.frame.size.width / 4, self.backButton.frame.size.width / 2, self.backButton.frame.size.width / 2)];
    self.backButtonImage.image = [UIImage imageNamed:@"iconfont-houtui.png"];
    [self.backButton addSubview:self.backButtonImage];
    
    //返回按钮方法
    [self.backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    //创建一个空View顶替系统LeftBar
    UIView *nilView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:nilView];
    
    //自定义右边View
    self.rightView = [[UIView alloc]initWithFrame:CGRectMake(self.backButton.frame.size.width + 1, 0, self.navigationController.navigationBar.frame.size.width - self.backButton.frame.size.width - 1, self.navigationController.navigationBar.frame.size.height)];
    self.rightView.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:self.rightView];
    
    //创建label(navigationItem.title)来显示每页标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.rightView.frame.size.height / 4, self.rightView.frame.size.height / 4, self.navigationController.navigationBar.frame.size.width / 5 * 3, self.rightView.frame.size.height / 2)];
    [self.rightView addSubview:self.titleLabel];
    
}


#pragma mark - 点击返回按钮的时候移除三个NavigationBar上的View
- (void)backAction:(UIButton *)backAction{
    [self.navigationController popViewControllerAnimated:YES];
    [self.backButton removeFromSuperview];
    [self.rightView removeFromSuperview];
    [self.titleLabel removeFromSuperview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
